package com.example.administrator.newxlmedical;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.baseproject.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import adapters.GoodsDetailsBarCodeAdapter;
import beans.GoodsDetailInfoBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import constants.Constants;
import utils.ActivityUtil;

/**
 * Created by Administrator on 2018/7/28.
 */

public class GoodsDetialActivity extends BaseActivity {


    @BindView(R.id.tv_goods_detail_title)
    TextView tvTitle;
    @BindView(R.id.tv_goods_detail_title_content)
    TextView tvTitleContent;
    @BindView(R.id.tv_goods_detail_name)
    TextView tvName;
    @BindView(R.id.tv_goods_detail_specification)
    TextView tvSpecification;
    @BindView(R.id.tv_goods_detail_supplier)
    TextView tvSupplier;
    @BindView(R.id.tv_goods_detail_number)
    TextView tvNumber;
    @BindView(R.id.tv_goods_detail_unit)
    TextView tvUnit;
    @BindView(R.id.tv_goods_detail_time)
    TextView tvTime;
    @BindView(R.id.ll_goods_detail_time)
    LinearLayout lllTime;
    @BindView(R.id.tv_goods_detail_operator)
    TextView tvOperator;
    @BindView(R.id.ll_goods_detail_operator)
    LinearLayout llOperator;
    @BindView(R.id.tv_goods_detail_status)
    TextView tvStatus;
    @BindView(R.id.rv_goods_detail_barCode)
    RecyclerView recyclerView;
    @BindView(R.id.iv_common_toolbar_home)
    ImageView ivHome;
    @BindView(R.id.iv_common_toolbar_back)
    ImageView ivBack;
    @BindView(R.id.tv_goods_detail_time_name)
    TextView tvTimeName;
    @BindView(R.id.tv_goods_detail_title_status)
    TextView tvTitleStatus;
    @BindView(R.id.tv_goods_detail_title_content3)
    TextView tvTitleContent3;
    @BindView(R.id.rl_goods_detail_icon3)
    RelativeLayout rlGoodsDetailIcon3;

    private List<String> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goods_detial);
        ButterKnife.bind(this);
        Bundle bundle = (Bundle) getIntent().getExtras().get("bundle");
        GoodsDetailInfoBean bean = (GoodsDetailInfoBean) bundle.getSerializable(Constants.GOODS_DETIAL_INFO);
        tvTitle.setText(bean.getTitle());
        tvTitleContent.setText(bean.getTitleContent());

        if (TextUtils.isEmpty(bean.getTitleThree())){
            rlGoodsDetailIcon3.setVisibility(View.GONE);
        }else {
            tvTitleContent3.setText(bean.getTitleThree());
        }

        tvName.setText(bean.getName());
        tvSpecification.setText(bean.getSpecification());
        tvSupplier.setText(bean.getSupplier());
        tvUnit.setText(bean.getUnit());
        tvNumber.setText(bean.getNumber() + "");

        String stutas;
        if (bean.getType() == 1) {
            if (bean.getStatus() == 1) {
                stutas = "未验收";
            } else if (bean.getStatus() == 2) {
                stutas = "已验收";
            } else if (bean.getStatus() == 3) {
                stutas = "已放入";
            } else if (bean.getStatus() == 4) {
                stutas = "已取出";
            } else if (bean.getStatus() == 5) {
                stutas = "已使用";
            } else if (bean.getStatus() == 6) {
                stutas = "已退货";
            }else if (bean.getStatus() == 12) {
                stutas = "未归审批";
            } else {
                stutas = bean.getStatus() + "";
            }
        } else {
            tvTitleStatus.setText("操作 : ");
            stutas = bean.getTypeStatus();
        }
        tvStatus.setText(stutas);

        if (TextUtils.isEmpty(bean.getTime())) {
            lllTime.setVisibility(View.GONE);
        } else {
            tvTimeName.setText(bean.getTimeName());
            tvTime.setText(bean.getTime());
        }

        if (TextUtils.isEmpty(bean.getOperator())) {
            llOperator.setVisibility(View.GONE);
        } else {
            tvOperator.setText(bean.getOperator());
        }

        list.addAll(bean.getBarCode());
        GoodsDetailsBarCodeAdapter adapter = new GoodsDetailsBarCodeAdapter(this, list);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);

    }

    @OnClick({R.id.iv_common_toolbar_home, R.id.iv_common_toolbar_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_common_toolbar_home:
                ActivityUtil.jumpToActivity(this, MainActivity.class);
                finish();
                break;
            case R.id.iv_common_toolbar_back:
                finish();
                break;
        }
    }
}
